package com.tanhua.server.controller;



import com.tanhua.dubbo.server.pojo.Voice;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.service.VoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("peachblossom")
public class VoiceController {
    /**
     *
     * 需要在tb_user_info表中添加一个字段times
     *
     *
     */

    @Autowired
    private VoiceService voiceService;

    @Autowired
    private TodayBestService todayBestService;

    /**
     * 上传语音
     * @param voiceFile
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> saveVoice(@RequestParam(value = "soundFile", required = false) MultipartFile voiceFile){
        return this.voiceService.saveVoice(voiceFile);
    }

    /**
     * 接收语音
     * @return
     */
    @GetMapping
    public Voice getVoice(){
        return this.voiceService.getVoice();
    }

    /**
     * 喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.todayBestService.likeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 不喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> disLikeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.todayBestService.disLikeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


}
